package cn.exrick.manager.service.impl;

import cn.exrick.manager.mapper.TbSysSettingMapper;
import cn.exrick.manager.pojo.TbSysSetting;
import cn.exrick.manager.pojo.TbSysSettingExample;
import cn.exrick.manager.service.SysSettingService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class SysSettingServiceImpl implements SysSettingService {

    @Autowired
    private TbSysSettingMapper tbSysSettingMapper;

    @Override
    public void updateSetting(TbSysSetting tbSysSetting) {
        tbSysSetting.setUpdateTime(new Date());
        tbSysSettingMapper.updateByPrimaryKeySelective(tbSysSetting);
    }


    @Override
    public TbSysSetting getSetting() {
        TbSysSettingExample example = new TbSysSettingExample();
        List<TbSysSetting> tbSysSettings = tbSysSettingMapper.selectByExample(example);
        if(CollectionUtils.isEmpty(tbSysSettings)){
            return null;
        }
        return tbSysSettings.get(0);
    }
}
